package is.client.controller.command;

import is.client.Locale;
import is.client.Main;
import is.common.exception.RowNotFoundException;
import is.common.exception.UniqueCheckFailedException;
import is.common.interfaces.Command;

import java.io.IOException;

/**
 * @author aspr0
 *         Date: 26.04.12
 *         Time: 5:51
 */
public class EditCommand implements Command
{
    private String[] row;
    private int sectionNum;

    public EditCommand(int sectionNum, String[] row)
    {
        this.row = row;
        this.sectionNum = sectionNum;
    }

    @Override
    public void execute()
    {
        try
        {
            Main.getController().getModel().editRow(sectionNum, row);
        }
        catch (UniqueCheckFailedException e)
        {
            Main.getController().getUserInterface().exposeWarnMsg(Locale.WARN_UNIQUE_CHECK_FAILED);
//            e.printStackTrace();
        }
        catch (RowNotFoundException e)
        {
            Main.getController().getUserInterface().exposeWarnMsg(Locale.WARN_ROW_NOT_FOUND);
//            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
    }
}
